{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3]\r\n"
     ]
    }
   ],
   "source": [
    "a = tf.constant([1,2,3],dtype= tf.float32)\n",
    "tf.print(a)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 3 5 7 9]\r\n"
     ]
    }
   ],
   "source": [
    "b = tf.range(1,10,delta=2)\n",
    "tf.print(b)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 0.0634343475 0.126868695 ... 6.15313148 6.21656609 6.28]\r\n"
     ]
    }
   ],
   "source": [
    "c = tf.linspace(0.0,2* 3.14,100)\n",
    "tf.print(c)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 0 0]\n",
      " [0 0 0]\n",
      " [0 0 0]]\r\n"
     ]
    }
   ],
   "source": [
    "d = tf.zeros([3,3])\n",
    "tf.print(d)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 1 1]\n",
      " [1 1 1]\n",
      " [1 1 1]]\r\n",
      "[[0 0 0]\n",
      " [0 0 0]\n",
      " [0 0 0]]\r\n"
     ]
    }
   ],
   "source": [
    "a = tf.ones([3,3])\n",
    "b = tf.zeros_like(a,dtype=tf.float32)\n",
    "tf.print(a)\n",
    "tf.print(b)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[5 5]\n",
      " [5 5]\n",
      " [5 5]]\r\n"
     ]
    }
   ],
   "source": [
    "b = tf.fill([3,2],5)\n",
    "tf.print(b)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1.65130854 9.01481247 6.30974197 4.34546089 2.9193902]\r\n"
     ]
    }
   ],
   "source": [
    "tf.random.set_seed(1.0)\n",
    "a = tf.random.uniform([5],minval=0,maxval=10)\n",
    "tf.print(a)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.403087884 -1.0880208 -0.0630953535]\n",
      " [1.33655667 0.711760104 -0.489286453]\n",
      " [-0.764221311 -1.03724861 -1.25193381]]\r\n"
     ]
    }
   ],
   "source": [
    "b = tf.random.normal([3,3],mean=0.0,stddev=1.0)\n",
    "tf.print(b)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.457012236 -0.406867266 0.728577733 -0.892977774 -0.369404584]\n",
      " [0.323488563 1.19383323 0.888299048 1.25985599 -1.95951891]\n",
      " [-0.202244401 0.294496894 -0.468728036 1.29494202 1.48142183]\n",
      " [0.0810953453 1.63843894 0.556645 0.977199793 -1.17777884]\n",
      " [1.67368948 0.0647980496 -0.705142677 -0.281972528 0.126546144]]\r\n"
     ]
    }
   ],
   "source": [
    "c = tf.random.truncated_normal((5,5),mean=0.0,stddev=1.0,dtype=tf.float32)\n",
    "tf.print(c)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 0 0]\n",
      " [0 1 0]\n",
      " [0 0 1]]\r\n",
      " \r\n",
      "[[1 0 0]\n",
      " [0 2 0]\n",
      " [0 0 3]]\r\n"
     ]
    }
   ],
   "source": [
    "I = tf.eye(3,3)\n",
    "tf.print(I)\n",
    "tf.print(\" \")\n",
    "t = tf.linalg.diag([1,2,3])\n",
    "tf.print(t)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[4 7 4 2 9]\n",
      " [9 1 2 4 7]\n",
      " [7 2 7 4 0]\n",
      " [9 6 9 7 2]\n",
      " [3 7 0 0 3]]\r\n"
     ]
    }
   ],
   "source": [
    "tf.random.set_seed(3)\n",
    "t = tf.random.uniform([5,5],minval=0,maxval=10,dtype=tf.int32)\n",
    "tf.print(t)\n",
    "\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4 7 4 2 9]\r\n"
     ]
    }
   ],
   "source": [
    "tf.print(t[0])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3 7 0 0 3]\r\n"
     ]
    }
   ],
   "source": [
    "tf.print(t[-1])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\r\n",
      "4\r\n"
     ]
    }
   ],
   "source": [
    "tf.print(t[1,3])\n",
    "tf.print(t[1][3])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[9 1 2 4 7]\n",
      " [7 2 7 4 0]\n",
      " [9 6 9 7 2]]\r\n",
      "[[9 1 2 4 7]\n",
      " [7 2 7 4 0]\n",
      " [9 6 9 7 2]]\r\n"
     ]
    }
   ],
   "source": [
    "tf.print(t[1:4,:])\n",
    "tf.print(tf.slice(t,[1,0],[3,5]))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[9 2]\n",
      " [7 7]\n",
      " [9 9]]\r\n"
     ]
    }
   ],
   "source": [
    "tf.print(t[1:4,:4:2])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [0 0]]\r\n"
     ]
    }
   ],
   "source": [
    "x = tf.Variable([[1,2],[3,4]],dtype=tf.float32)\n",
    "x[1,:].assign(tf.constant([0.0,0.0]))\n",
    "tf.print(x)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[7 3 9]\n",
      "  [9 0 7]\n",
      "  [9 6 7]]\n",
      "\n",
      " [[1 3 3]\n",
      "  [0 8 1]\n",
      "  [3 1 0]]\n",
      "\n",
      " [[4 0 6]\n",
      "  [6 2 2]\n",
      "  [7 9 5]]]\r\n"
     ]
    }
   ],
   "source": [
    "a = tf.random.uniform([3,3,3],minval=0,maxval=10,dtype=tf.int32)\n",
    "tf.print(a)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[3 0 6]\n",
      " [3 8 1]\n",
      " [0 2 9]]\r\n"
     ]
    }
   ],
   "source": [
    "tf.print(a[...,1])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[52 82 66 ... 17 86 14]\n",
      "  [8 36 94 ... 13 78 41]\n",
      "  [77 53 51 ... 22 91 56]\n",
      "  ...\n",
      "  [11 19 26 ... 89 86 68]\n",
      "  [60 72 0 ... 11 26 15]\n",
      "  [24 99 38 ... 97 44 74]]\n",
      "\n",
      " [[79 73 73 ... 35 3 81]\n",
      "  [83 36 31 ... 75 38 85]\n",
      "  [54 26 67 ... 60 68 98]\n",
      "  ...\n",
      "  [20 5 18 ... 32 45 3]\n",
      "  [72 52 81 ... 88 41 20]\n",
      "  [0 21 89 ... 53 10 90]]\n",
      "\n",
      " [[52 80 22 ... 29 25 60]\n",
      "  [78 71 54 ... 43 98 81]\n",
      "  [21 66 53 ... 97 75 77]\n",
      "  ...\n",
      "  [6 74 3 ... 53 65 43]\n",
      "  [98 36 72 ... 33 36 81]\n",
      "  [61 78 70 ... 7 59 21]]\n",
      "\n",
      " [[56 57 45 ... 23 15 3]\n",
      "  [35 8 82 ... 11 59 97]\n",
      "  [44 6 99 ... 81 60 27]\n",
      "  ...\n",
      "  [76 26 35 ... 51 8 17]\n",
      "  [33 52 53 ... 78 37 31]\n",
      "  [71 27 44 ... 0 52 16]]]\r\n"
     ]
    }
   ],
   "source": [
    "scores = tf.random.uniform((4,10,7),minval=0,maxval=100,dtype=tf.int32)\n",
    "tf.print(scores)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[52 82 66 ... 17 86 14]\n",
      "  [24 80 70 ... 72 63 96]\n",
      "  [24 99 38 ... 97 44 74]]\n",
      "\n",
      " [[79 73 73 ... 35 3 81]\n",
      "  [46 10 94 ... 23 18 92]\n",
      "  [0 21 89 ... 53 10 90]]\n",
      "\n",
      " [[52 80 22 ... 29 25 60]\n",
      "  [19 12 23 ... 87 86 25]\n",
      "  [61 78 70 ... 7 59 21]]\n",
      "\n",
      " [[56 57 45 ... 23 15 3]\n",
      "  [6 41 79 ... 97 43 13]\n",
      "  [71 27 44 ... 0 52 16]]]\r\n"
     ]
    }
   ],
   "source": [
    "p = tf.gather(scores,[0,5,9],axis=1)\n",
    "tf.print(p)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[82 55 14]\n",
      "  [80 46 96]\n",
      "  [99 58 74]]\n",
      "\n",
      " [[73 48 81]\n",
      "  [10 38 92]\n",
      "  [21 86 90]]\n",
      "\n",
      " [[80 57 60]\n",
      "  [12 34 25]\n",
      "  [78 71 21]]\n",
      "\n",
      " [[57 75 3]\n",
      "  [41 47 13]\n",
      "  [27 96 16]]]\r\n"
     ]
    }
   ],
   "source": [
    "q = tf.gather(tf.gather(scores,[0,5,9],axis=1),[1,3,6],axis=2)\n",
    "tf.print(q)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "outputs": [
    {
     "data": {
      "text/plain": "<tf.Tensor: shape=(3, 7), dtype=int32, numpy=\narray([[52, 82, 66, 55, 17, 86, 14],\n       [99, 94, 46, 70,  1, 63, 41],\n       [46, 83, 70, 80, 90, 85, 17]])>"
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = tf.gather_nd(scores,indices=[(0,0),(2,4),(3,6)])\n",
    "s"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[52 82 66 ... 17 86 14]\n",
      "  [24 80 70 ... 72 63 96]\n",
      "  [24 99 38 ... 97 44 74]]\n",
      "\n",
      " [[79 73 73 ... 35 3 81]\n",
      "  [46 10 94 ... 23 18 92]\n",
      "  [0 21 89 ... 53 10 90]]\n",
      "\n",
      " [[52 80 22 ... 29 25 60]\n",
      "  [19 12 23 ... 87 86 25]\n",
      "  [61 78 70 ... 7 59 21]]\n",
      "\n",
      " [[56 57 45 ... 23 15 3]\n",
      "  [6 41 79 ... 97 43 13]\n",
      "  [71 27 44 ... 0 52 16]]]\r\n"
     ]
    }
   ],
   "source": [
    "p = tf.boolean_mask(scores,[True,False,False,False,False,\n",
    "                            True,False,False,False,True],axis=1)\n",
    "tf.print(p)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[52 82 66 ... 17 86 14]\n",
      " [99 94 46 ... 1 63 41]\n",
      " [46 83 70 ... 90 85 17]]\r\n"
     ]
    }
   ],
   "source": [
    "s = tf.boolean_mask(scores,\n",
    "    [[True,False,False,False,False,False,False,False,False,False],\n",
    "     [False,False,False,False,False,False,False,False,False,False],\n",
    "     [False,False,False,False,True,False,False,False,False,False],\n",
    "     [False,False,False,False,False,False,True,False,False,False]])\n",
    "tf.print(s)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-1 1 -1]\n",
      " [2 2 -2]\n",
      " [3 -3 3]] \n",
      "\r\n",
      "[-1 -1 -2 -3] \n",
      "\r\n",
      "[-1 -1 -2 -3]\r\n"
     ]
    }
   ],
   "source": [
    "c = tf.constant([[-1,1,-1],[2,2,-2],[3,-3,3]],dtype=tf.float32)\n",
    "tf.print(c,\"\\n\")\n",
    "tf.print(tf.boolean_mask(c,c<0),\"\\n\")\n",
    "tf.print(c[c<0])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "outputs": [
    {
     "data": {
      "text/plain": "<tf.Tensor: shape=(3, 3), dtype=float32, numpy=\narray([[nan,  1., nan],\n       [ 2.,  2., nan],\n       [ 3., nan,  3.]], dtype=float32)>"
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = tf.constant([[-1,1,-1],[2,2,-2],[3,-3,3]],dtype=tf.float32)\n",
    "d = tf.where(c< 0,tf.fill(c.shape,np.nan),c)\n",
    "d"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "outputs": [
    {
     "data": {
      "text/plain": "<tf.Tensor: shape=(4, 2), dtype=int64, numpy=\narray([[0, 0],\n       [0, 2],\n       [1, 2],\n       [2, 1]], dtype=int64)>"
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "indices = tf.where(c < 0)\n",
    "indices\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "outputs": [
    {
     "data": {
      "text/plain": "<tf.Tensor: shape=(3, 3), dtype=float32, numpy=\narray([[ 0.,  1., -1.],\n       [ 2.,  2., -2.],\n       [ 3.,  0.,  3.]], dtype=float32)>"
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = c - tf.scatter_nd([[0,0],[2,1]],[c[0,0],c[2,1]],c.shape)\n",
    "d"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TensorShape([1, 3, 3, 2])\r\n",
      "[[[[100 44]\n",
      "   [181 14]\n",
      "   [90 53]]\n",
      "\n",
      "  [[205 141]\n",
      "   [14 24]\n",
      "   [239 46]]\n",
      "\n",
      "  [[225 174]\n",
      "   [212 78]\n",
      "   [14 144]]]]\r\n"
     ]
    }
   ],
   "source": [
    "a = tf.random.uniform(shape=[1,3,3,2],\n",
    "                      minval=0,maxval=255,dtype=tf.int32)\n",
    "tf.print(a.shape)\n",
    "tf.print(a)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TensorShape([3, 6])\r\n",
      "[[100 44 181 14 90 53]\n",
      " [205 141 14 24 239 46]\n",
      " [225 174 212 78 14 144]]\r\n"
     ]
    }
   ],
   "source": [
    "b = tf.reshape(a,[3,6])\n",
    "tf.print(b.shape)\n",
    "tf.print(b)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TensorShape([3, 3, 2])\r\n",
      "[[[100 44]\n",
      "  [181 14]\n",
      "  [90 53]]\n",
      "\n",
      " [[205 141]\n",
      "  [14 24]\n",
      "  [239 46]]\n",
      "\n",
      " [[225 174]\n",
      "  [212 78]\n",
      "  [14 144]]]\r\n"
     ]
    }
   ],
   "source": [
    "s = tf.squeeze(a)\n",
    "tf.print(s.shape)\n",
    "tf.print(s)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "outputs": [
    {
     "data": {
      "text/plain": "<tf.Tensor: shape=(1, 3, 3, 2), dtype=int32, numpy=\narray([[[[100,  44],\n         [181,  14],\n         [ 90,  53]],\n\n        [[205, 141],\n         [ 14,  24],\n         [239,  46]],\n\n        [[225, 174],\n         [212,  78],\n         [ 14, 144]]]])>"
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = tf.expand_dims(s,axis=0)\n",
    "d"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TensorShape([100, 600, 600, 4])\r\n",
      "TensorShape([4, 600, 600, 100])\r\n"
     ]
    }
   ],
   "source": [
    "a = tf.random.uniform(shape=[100,600,600,4],minval=0,maxval=255,dtype=tf.int32)\n",
    "tf.print(a.shape)\n",
    "\n",
    "s = tf.transpose(a,perm=[3,1,2,0])\n",
    "tf.print(s.shape)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "outputs": [
    {
     "data": {
      "text/plain": "<tf.Tensor: shape=(6, 2), dtype=int32, numpy=\narray([[ 1,  2],\n       [ 3,  4],\n       [ 5,  6],\n       [ 7,  8],\n       [ 9, 10],\n       [11, 12]])>"
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = tf.constant([[1,2],[3,4]])\n",
    "b = tf.constant([[5,6],[7,8]])\n",
    "c = tf.constant([[9,10],[11,12]])\n",
    "tf.concat([a,b,c],axis= 0)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "outputs": [
    {
     "data": {
      "text/plain": "<tf.Tensor: shape=(2, 6), dtype=int32, numpy=\narray([[ 1,  2,  5,  6,  9, 10],\n       [ 3,  4,  7,  8, 11, 12]])>"
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tf.concat([a,b,c],axis=1)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "outputs": [
    {
     "data": {
      "text/plain": "<tf.Tensor: shape=(3, 2, 2), dtype=int32, numpy=\narray([[[ 1,  2],\n        [ 3,  4]],\n\n       [[ 5,  6],\n        [ 7,  8]],\n\n       [[ 9, 10],\n        [11, 12]]])>"
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tf.stack([a,b,c])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "outputs": [
    {
     "data": {
      "text/plain": "<tf.Tensor: shape=(2, 3, 2), dtype=int32, numpy=\narray([[[ 1,  2],\n        [ 5,  6],\n        [ 9, 10]],\n\n       [[ 3,  4],\n        [ 7,  8],\n        [11, 12]]])>"
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tf.stack([a,b,c],axis=1)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "outputs": [
    {
     "data": {
      "text/plain": "[<tf.Tensor: shape=(2, 2), dtype=float32, numpy=\n array([[1., 2.],\n        [3., 4.]], dtype=float32)>,\n <tf.Tensor: shape=(2, 2), dtype=float32, numpy=\n array([[5., 6.],\n        [7., 8.]], dtype=float32)>,\n <tf.Tensor: shape=(2, 2), dtype=float32, numpy=\n array([[ 9., 10.],\n        [11., 12.]], dtype=float32)>]"
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = tf.constant([[1.0,2.0],[3.0,4.0]])\n",
    "b = tf.constant([[5.0,6.0],[7.0,8.0]])\n",
    "c = tf.constant([[9.0,10.0],[11.0,12.0]])\n",
    "\n",
    "c = tf.concat([a,b,c],axis = 0)\n",
    "tf.split(c,3,axis=0)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "outputs": [
    {
     "data": {
      "text/plain": "[<tf.Tensor: shape=(2, 2), dtype=float32, numpy=\n array([[1., 2.],\n        [3., 4.]], dtype=float32)>,\n <tf.Tensor: shape=(2, 2), dtype=float32, numpy=\n array([[5., 6.],\n        [7., 8.]], dtype=float32)>,\n <tf.Tensor: shape=(2, 2), dtype=float32, numpy=\n array([[ 9., 10.],\n        [11., 12.]], dtype=float32)>]"
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tf.split(c,[2,2,2],axis = 0) #指定每份的记录数量\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}